{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0b37b013",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Matplotlib is building the font cache; this may take a moment.\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "os.environ[\"KMP_DUPLICATE_LIB_OK\"]=\"TRUE\"\n",
    "import torch\n",
    "import torch.nn as nn\n",
    "import matplotlib.pyplot as plt\n",
    "from torch.autograd import Variable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9a4506d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#超参数\n",
    "input_size = 1\n",
    "output_size = 1\n",
    "num_epochs = 1000\n",
    "learning_rate = 0.001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "89ac3bed",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e6184f96",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train = np.array([[2.3],[4.4],[3.7],[6.1],[7.3],[2.1],[5.6],[7.7],[7.7],[4.1],\n",
    "                   [6.7],[6.1],[7.5],[2.1],[7.2],\n",
    "                   [5.6],[5.7],[7.7],[3.1]],dtype=np.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d647840f",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train = np.array([[2.7],[4.76],[4.1],[7.1],[7.6],[3.5],[5.4],[7.6],[7.9],[5.3],\n",
    "                   [7.3],[7.5],[7.5],[3.2],[7.7],\n",
    "                   [6.4],[6.6],[7.9],[4.9]],dtype=np.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "84a58e81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function matplotlib.pyplot.show(close=None, block=None)>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "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mT16SCma7RpIKZrtGAy0izgH+ccHhH2fmuf2oR6qa7RpJKpjtGkkqmCEvSQUz5CWpYIa8JBXs/wHpPRfpP+6ocAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure()#画图\n",
    "plt.scatter(x_train,y_train)\n",
    "plt.xlabel(\"x_axis\")\n",
    "plt.ylabel(\"y_axis\")\n",
    "plt.show"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "6374017b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LinearRegression(\n",
      "  (linear): Linear(in_features=1, out_features=1, bias=True)\n",
      ")\n"
     ]
    }
   ],
   "source": [
    "#建立回归模型\n",
    "class LinearRegression(nn.Module):\n",
    "    def __init__(self,input_size,output_size):\n",
    "        super(LinearRegression,self).__init__()\n",
    "        self.linear = nn.Linear(input_size,output_size)\n",
    "    def forward(self, x):\n",
    "        out = self.linear(x)\n",
    "        return out\n",
    "    \n",
    "#实例化\n",
    "model = LinearRegression(input_size,output_size)\n",
    "print(model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "eeb71f2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#损失函数\n",
    "criterion = nn.MSELoss()#均方误差函数\n",
    "#优化函数\n",
    "optimizer = torch.optim.SGD(model.parameters(),lr=learning_rate)#随机梯度下降算法SGD"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "7c1519c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch[500/1000],loss:0.2343\n",
      "Epoch[1000/1000],loss:0.2281\n",
      "Epoch[1500/1000],loss:0.2231\n",
      "Epoch[2000/1000],loss:0.2192\n",
      "Epoch[2500/1000],loss:0.2160\n",
      "Epoch[3000/1000],loss:0.2135\n",
      "Epoch[3500/1000],loss:0.2115\n",
      "Epoch[4000/1000],loss:0.2099\n",
      "Epoch[4500/1000],loss:0.2086\n",
      "Epoch[5000/1000],loss:0.2076\n",
      "Epoch[5500/1000],loss:0.2067\n",
      "Epoch[6000/1000],loss:0.2061\n",
      "Epoch[6500/1000],loss:0.2055\n",
      "Epoch[7000/1000],loss:0.2051\n",
      "Epoch[7500/1000],loss:0.2048\n",
      "Epoch[8000/1000],loss:0.2045\n",
      "Epoch[8500/1000],loss:0.2043\n",
      "Epoch[9000/1000],loss:0.2041\n",
      "Epoch[9500/1000],loss:0.2040\n",
      "Epoch[10000/1000],loss:0.2039\n"
     ]
    }
   ],
   "source": [
    "#训练模型\n",
    "for epoch in range(num_epochs*10):\n",
    "    #NumPy转化成Tensor\n",
    "    inputs  = Variable(torch.from_numpy(x_train))\n",
    "    targets = Variable(torch.from_numpy(y_train))\n",
    "    \n",
    "    #前向传播\n",
    "    optimizer.zero_grad()  #梯度归零\n",
    "    outputs = model(inputs)\n",
    "    #反向传播\n",
    "    loss = criterion(outputs, targets)\n",
    "    loss.backward()\n",
    "    #优化\n",
    "    optimizer.step()\n",
    "    #更新参数\n",
    "    if(epoch+1)%500 == 0:\n",
    "        print('Epoch[%d/%d],loss:%.4f' %(epoch+1,num_epochs,loss.item()))#隔50个epoch打印一次结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "2220468e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAcr0lEQVR4nO3de3xU9ZkG8OdNQGNiQAvBGyYTBQmKXFMEk4ICIhDE1eqqDW3Vrmmp17LKBqOilmCorla7lTZqvXWkpVS31QgiC1QR0QYEu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ERLHh6IOIyOUY1ERELmd7UIvI2SKyWEQ2iMg6EbnT7h6sICJJIvKhiKyOvK+HnO7JTCKSKCIficgbTvdiJhEJicgaEVklIuVO92MWETlFROaKyMbI/2tDne7JDCLSK/Lv6ug/e0TkLqf7sprtM2oROQPAGaq6UkRSAawA8G+qut7WRkwmIgIgRVX3iUhHAEsB3Kmqyx1uzRQiMhlANoBOqjre6X7MIiIhANmq6qmLJ0TkRQDvquqzInICgGRV3e1wW6YSkUQAnwG4SFVbusAurtl+RK2qn6vqysif9wLYAOAsu/swm4bti3zaMfKPJ87Uikh3AHkAnnW6F2qZiHQCMAzAcwCgqoe8FtIRIwFUeD2kAYdn1CISADAAwAdO9mGWyHhgFYAvAbytqp54XwB+DWAKgHqH+7CCAlggIitEpMDpZkxyDoAdAJ6PjKueFZEUp5uywPUAZjvdhB0cC2oRORnAXwHcpap7nOrDTKpap6r9AXQHMFhE+jjcUruJyHgAX6rqCqd7sUiOqg4EMBbArSIyzOmGTNABwEAAs1R1AID9AAqdbclckXHOBAB/cboXOzgS1JEZ7l8BBFX1VSd6sFLk18wlAMY424kpcgBMiMxy/wRghIj80dmWzKOq2yIfvwTwGoDBznZkimoA1Q1+o5uLcHB7yVgAK1V1u9ON2MGJVR+C8Oxsg6o+bvfrW0VE0kTklMifTwIwCsBGR5sygapOVdXuqhpA+FfNRao60eG2TCEiKZET2oiMBkYDWOtsV+2nql8A+FREekVKIwHE9cn6KG6AT8YegDOb2+YA+CGANZF5LgDcq6pvOtCLmc4A8GLkTHQCgDmq6qmlbB50GoDXwscO6ADgFVWd72xLprkdQDAyItgC4CaH+zGNiCQDuAzAT53uxS68hJyIyOV4ZSIRkcsxqImIXI5BTUTkcgxqIiKXY1ATEbkcg5qIyOUY1ERELvf/+AjdrSbXISgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#测试模型\n",
    "model.eval()#将模型变为测试模式\n",
    "predicted = model(Variable(torch.from_numpy(x_train))).data.numpy()\n",
    "plt.plot(x_train,y_train,'ro')\n",
    "plt.plot(x_train, predicted, label=\"predict\")\n",
    "plt.legend() #画标签\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d79f4cc6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
